﻿
''' <summary>
''' Thanh lý tài sản
''' </summary>
''' <remarks></remarks>
Public Class DisposalDTO
    Inherits Disposal_X


    Private _id As Integer ' Mã tài sản
    Private _councilDisposal As Integer ' Hội đồng thanh lý
    Private _cost As Integer ' Nguyên giá
    Private _costImpoverishment As Integer ' Số hao mòn
    Private _costRemaining As Integer ' Giá trị còn lại
    Private _costDisposal As Integer ' Chi phí thanh lý
    Private _contentDisposal As String ' Nội dung thanh lý
    Private _date As Date ' Thời gian
    Private _place As String ' Địa điểm
    Private _fatype As Integer ' Loại tài sản
    Private _status As Integer ' Trạng thái chứng từ

    Private _behave As Integer



    Public Sub New(ByVal id As Integer, ByVal councilDisposal As Integer, ByVal cost As Integer, ByVal costImpoverishment As Integer, ByVal costRemaining As Integer, ByVal costDisposal As Integer, ByVal contentDisposal As String, ByVal date1 As Date, ByVal place As String, ByVal fatype As Integer)
        Me._id = id
        Me._councilDisposal = contentDisposal
        Me._cost = cost
        Me._costImpoverishment = costImpoverishment
        Me._costRemaining = costRemaining
        Me._costDisposal = costDisposal
        Me._contentDisposal = contentDisposal
        Me._date = date1
        Me._place = place
        Me._fatype = fatype
        Me._status = CONSTANT.STATUS._DRAFTS

        Me._behave = CONSTANT.BEHAVE_TYPE._INSERT

    End Sub

    Public Sub New(ByVal id As Integer)
        Dim myConnect As MySqlConnect
        myConnect = New MySqlConnect

        Dim aSql As String
        aSql = "SELECT *FROM " & MyBase.TABLE_NAME & ""
        aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & id & ""

        Dim da As DataTable
        da = New DataTable
        da = myConnect.executeQuery(aSql)

        If (da Is Nothing) Then
            Return
        End If
        Me._id = CType(da.Rows(0)(MyBase.COLUMN_NAME_id), Integer)
        Me._councilDisposal = CType(da.Rows(0)(MyBase.COLUMN_NAME_councilDisposal), Integer)
        Me._cost = CType(da.Rows(0)(MyBase.COLUMN_NAME_cost), Integer)
        Me._costImpoverishment = CType(da.Rows(0)(MyBase.COLUMN_NAME_costImpoverishment), Integer)
        Me._costRemaining = CType(da.Rows(0)(MyBase.COLUMN_NAME_costRemaining), Integer)
        Me._costDisposal = CType(da.Rows(0)(MyBase.COLUMN_NAME_costDisposal), Integer)
        Me._contentDisposal = CType(da.Rows(0)(MyBase.COLUMN_NAME_contentDisposal), String)
        Me._date = CType(da.Rows(0)(MyBase.COLUMN_NAME_date), Date)
        Me._place = CType(da.Rows(0)(MyBase.COLUMN_NAME_place), String)
        Me._fatype = CType(da.Rows(0)(MyBase.COLUMN_NAME_fatype), Integer)
        Me._status = CType(da.Rows(0)(MyBase.COLUMN_NAME_status), Integer)

        Me._behave = CONSTANT.BEHAVE_TYPE._UPDATE


    End Sub


    Public Function save() As Boolean
        Dim myConnect As MySqlConnect
        myConnect = New MySqlConnect
        Dim aSql As String
        aSql = ""
        Select Case Me._behave
            Case CONSTANT.BEHAVE_TYPE._UPDATE
                aSql = "UPDATE " & MyBase.TABLE_NAME & ""
                aSql += " SET " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
                aSql += " ," & MyBase.COLUMN_NAME_councilDisposal & " = " & Me._councilDisposal & ""
                aSql += " ," & MyBase.COLUMN_NAME_cost & " = " & Me._cost & ""
                aSql += " ," & MyBase.COLUMN_NAME_costImpoverishment & " = " & Me._costImpoverishment & ""
                aSql += " ," & MyBase.COLUMN_NAME_costRemaining & " = " & Me._costRemaining & ""
                aSql += " ," & MyBase.COLUMN_NAME_costDisposal & " = " & Me._costDisposal & ""
                aSql += " ," & MyBase.COLUMN_NAME_contentDisposal & " = " & Me._contentDisposal & ""
                aSql += " ," & MyBase.COLUMN_NAME_date & " = " & Me._date & ""
                aSql += " ," & MyBase.COLUMN_NAME_place & " = " & Me._place & ""
                aSql += " ," & MyBase.COLUMN_NAME_fatype & " = " & Me._fatype & ""
                aSql += " ," & MyBase.COLUMN_NAME_status & " = " & Me._status & ""
                aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
                Return myConnect.executeUpdate(aSql)

            Case CONSTANT.BEHAVE_TYPE._INSERT
                aSql = "INSERT INTO " & MyBase.TABLE_NAME & ""
                aSql += " ("
                aSql += " " & MyBase.COLUMN_NAME_id & ""
                aSql += " ," & MyBase.COLUMN_NAME_councilDisposal & ""
                aSql += " ," & MyBase.COLUMN_NAME_cost & ""
                aSql += " ," & MyBase.COLUMN_NAME_costImpoverishment & ""
                aSql += " ," & MyBase.COLUMN_NAME_costRemaining & ""
                aSql += " ," & MyBase.COLUMN_NAME_costDisposal & ""
                aSql += " ," & MyBase.COLUMN_NAME_contentDisposal & ""
                aSql += " ," & MyBase.COLUMN_NAME_date & ""
                aSql += " ," & MyBase.COLUMN_NAME_place & ""
                aSql += " ," & MyBase.COLUMN_NAME_fatype & ""
                aSql += " ," & MyBase.COLUMN_NAME_status & ""
                aSql += " )"
                aSql += " VALUES("
                aSql += " " & Me._id & ""
                aSql += " ," & Me._councilDisposal & ""
                aSql += " ," & Me._cost & ""
                aSql += " ," & Me._costImpoverishment & ""
                aSql += " ," & Me._costRemaining & ""
                aSql += " ," & Me._costDisposal & ""
                aSql += " ," & Me._contentDisposal & ""
                aSql += " ," & Me._date & ""
                aSql += " ," & Me._place & ""
                aSql += " ," & Me._fatype & ""
                aSql += " ," & Me._status & ""
                aSql += " )"
                Return myConnect.executeUpdate(aSql)
            Case Else
        End Select
    End Function

    Public Function delete() As Boolean
        Dim myConnect As MySqlConnect
        myConnect = New MySqlConnect
        Dim aSql As String
        aSql = "DELETE FROM " & MyBase.TABLE_NAME & ""
        aSql += " WHERE " & MyBase.COLUMN_NAME_id & " = " & Me._id & ""
        Return myConnect.executeUpdate(aSql)

    End Function

    Public Property id() As Integer
        Get
            Return Me._id
        End Get
        Set(ByVal value As Integer)
            Me._id = value
        End Set
    End Property

    Public Property councilDisposal() As Integer
        Get
            Return Me._councilDisposal
        End Get
        Set(ByVal value As Integer)
            Me._councilDisposal = value
        End Set
    End Property

    Public Property cost() As Integer
        Get
            Return Me._cost
        End Get
        Set(ByVal value As Integer)
            Me._cost = value
        End Set
    End Property

    Public Property costImpoverishment() As Integer
        Get
            Return Me._costImpoverishment
        End Get
        Set(ByVal value As Integer)
            Me._costImpoverishment = value
        End Set
    End Property
    Public Property costRemaining() As Integer
        Get
            Return Me._costRemaining
        End Get
        Set(ByVal value As Integer)
            Me._costRemaining = value
        End Set
    End Property

    Public Property costDisposal() As Integer
        Get
            Return Me._costDisposal
        End Get
        Set(ByVal value As Integer)
            Me._costDisposal = value
        End Set
    End Property

    Public Property contentDisposal() As String
        Get
            Return Me._contentDisposal
        End Get
        Set(ByVal value As String)
            Me._contentDisposal = value
        End Set
    End Property

    Public Property datetime() As Date
        Get
            Return Me._date
        End Get
        Set(ByVal value As Date)
            Me._date = value
        End Set
    End Property

    Public Property place() As String
        Get
            Return Me._place
        End Get
        Set(ByVal value As String)
            Me._place = value
        End Set
    End Property

    Public Property fatype() As Integer
        Get
            Return Me._fatype
        End Get
        Set(ByVal value As Integer)
            Me._fatype = value
        End Set
    End Property

    Public Property status() As Integer
        Get
            Return Me._status
        End Get
        Set(ByVal value As Integer)
            Me._status = value
        End Set
    End Property

End Class
